package org.greenwire;

import org.greenwire.util.Constants;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * @author wei.zhongw
 * @since 2010-7-6
 */
public class DBHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = Constants.ACCOUNT_BOOK;
	private static final int DATABASE_VERSION = 1;
	private static final String LOG_TAG = Constants.LOG_TAG + "DBHelper";
	
	public DBHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		String sql = 
			"create table if not exists account_book (" + 
				Constants.KEY_ROW_ID + " integer primary key autoincrement, " +
				Constants.KEY_CONTENT + " text not null, " +
				Constants.KEY_PRICE + " decimal(10,5) not null, " +
				Constants.KEY_TYPE + " TINYINT not null, " +
				Constants.KEY_CATEGORY + " integer not null, " +
				Constants.KEY_GMT_HAPPENED + " text);";
		try{
			db.execSQL(sql);
			Log.i(LOG_TAG, "create table successful : [" + sql + "]");
		} catch (SQLException se){
			Log.e(LOG_TAG, se.getMessage(), se);
		}
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	}	
}
